home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2291 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What should be returned?
  5. Date: 19 Jan 1996 22:44 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <19JAN199622440915@erich.triumf.ca>
  9. References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk> <DLEvrv.K85@freenet.durham.org>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <DLEvrv.K85@freenet.durham.org>, cschmidt@freenet.durham.org (Chris Schmidt) writes...
  14. >the CAReLess boy (phsung@cs.cuhk.hk) wrote:
  15.  
  16. >:     It's said that the function main must return an integer value
  17. >: but I just don't know what value should be returned.  Also, if I quit
  18. >: main by exit(), what's the use of the return value?
  19.  
  20. >I myself am just starting to learn this stuff too, but from what I have 
  21. >read so far.. if you do not require an exit value from the program use:
  22. >void main(void)
  23.  
  24. You had better read a little further (but not in Schildt's books...)
  25.  
  26. In spite of many introductory books to the contary, the C standard _requires_
  27. that main() return an int.  In many operating systems, this return value can be
  28. tested to determine something about the exit status of a program.  Under
  29. MS-DOs, this is done in batch files using "if errorlevel", where errorlevel is
  30. the value returned from main() (or returned by exit()).  Some programs that
  31. call others, such as Make, and compiler IDEs, use this value to determine
  32. whether or not to continue with a process.
  33.  
  34. Under DOS, and probably unix, it is up to the user, or a program such as make,
  35. to test this value - the operating system doesn't care itself, but some other
  36. operating systems may take a more direct interest in the return value.
  37.  
  38. stdlib.h #defines EXIT_SUCCESS and EXIT_FAILURE for use as portable return
  39. codes.
  40.  
  41.  
  42.  
  43. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  44. Internet: bennett@triumf.ca         | of one another only when one can be
  45. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  46. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  47. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  48.  
  49.